package com.bwie.controller;

import com.bwie.common.domain.Home;
import com.bwie.common.domain.Organization;
import com.bwie.common.domain.request.OrganizationListReq;
import com.bwie.common.domain.response.OrganizationListResp;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.service.OrganizationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @className: OrganizationController
 * @Description: TODO
 * @version: v1.８.0
 * @author: 李明
 * @date: 2025/10/22 11:04
 */
@RestController
@RequestMapping("organization")
@CrossOrigin
public class OrganizationController {

    @Autowired
    private OrganizationService organizationService;


//    /**
//     * 菜单树
//     * @return
//     */
//    @GetMapping("homeList/{userId}")
//    public Result<List<Home>> homeList(@PathVariable("userId") Integer userId){
//        List<Home> homeList = organizationService.homeList(userId);
//        return Result.error(homeList);
//    }


    /**
     * 分页组织查询
     * @return
     */
    @PostMapping("organizationList")
    public Result<PageResult<OrganizationListResp>> organizationList(@RequestBody OrganizationListReq organizationListReq){
        PageHelper.startPage(organizationListReq.getPageNum(),organizationListReq.getPageSize());
        List<OrganizationListResp> organizationListRespList = organizationService.organizationList(organizationListReq);
        PageInfo<OrganizationListResp> organizationListRespPageInfo = new PageInfo<>(organizationListRespList);
        //分页
        return PageResult.toResult(organizationListRespPageInfo.getTotal(),organizationListRespList);
    }

    /**
     * 添加
     */
    @PostMapping("addOrganizationInfo")
    public Result addOrganizationInfo(@RequestBody Organization organization){
        organizationService.addOrganizationInfo(organization);
        return Result.success();
    }

}
